package at.sysarch.filter;

import java.awt.image.renderable.ParameterBlock;

import javax.media.jai.JAI;
import javax.media.jai.KernelJAI;

import at.pimpmypipe.filter.DataEnrichmentFilter;
import at.sysarch.bean.AbstractBean;
import at.sysarch.domain.TransferImage;
import at.sysarch.utils.KernelHelper;

public class DilateFilter extends DataEnrichmentFilter<TransferImage, TransferImage> {
	
	private KernelJAI _kernel = KernelHelper.getKernel(12, 12);
	
	public DilateFilter(AbstractBean<DilateFilter> bean) {
		super(bean);
	}

	@Override
	protected boolean fillEntity(TransferImage nextVal, TransferImage entity) {

		entity.setSourceImage(nextVal.getSourceImage());
		
		ParameterBlock erodeParams = new ParameterBlock();
		
		erodeParams.addSource(nextVal.getModifiedImage());
		erodeParams.add(_kernel);
		
		entity.setModifiedImage(JAI.create("erode", erodeParams));
		_bean.displayImage(entity);
		return true;
	}

	@Override
	protected TransferImage getNewEntityObject() {

		return new TransferImage();
	}
	
	public void setKernel(KernelJAI kernel) {
		_kernel = kernel;
	}
	
	public KernelJAI getKernel() {
		
		return _kernel;
	}
}
